package org.example.service;

import org.example.dao.DepartmentDAO;
import org.example.entity.Department;
import org.example.utils.DataUtils;
import org.example.utils.TableUtils;
import org.example.utils.TimeUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;

public class DepartmentService {
    public static boolean addDepartment(String departName) {

        Department department = new Department();
        department.setDptId(UUID.randomUUID().toString());
        department.setDptName(departName);
        department.setCreateTime(TimeUtils.getTime());
        department.setUpdateTime(TimeUtils.getTime());
        //dao新增
        return DepartmentDAO.insertDepartment(department);

    }

    public static ArrayList<String[]> queryDepartment() {
        return DepartmentDAO.getDepartmentInfo();
    }

    public static boolean updateDepartment(String id,String newDepartName) {
        if (DepartmentDAO.updateDepartment(id, newDepartName)){
            //同步更新员工code
            return EmployeeService.updateEmployeeEmpCode(id, newDepartName);
        }else{
            return false;
        }
    }

    public static boolean deleteDepartment(String id) {
        //dao删除
        return DepartmentDAO.deleteDepartment(id);
    }

    public static boolean queryDepartmentByName(String departName) {
        return DepartmentDAO.queryDepartmentByName(departName);
    }

    public static ArrayList<String[]> getDepartmentInfo() {
        return DepartmentDAO.getDepartmentInfo();
    }
}
